#ifndef __LOG_CLIENT_H
#define __LOG_CLIENT_H

#include <arpa/inet.h>

#include "SysLog.h"


static std::string GetLogLevelStr(LOG_LEVEL nLogLevel);
static LOG_LEVEL GetLogLevelEnum(const std::string &strLogLevel);


int AddLog(LOG_LEVEL nAddLogLevel, const std::string &strSource, const char* logInfo, ...);
int QueryLog(int nLogCount, const std::string strKeyWord, std::string &strResult);
int ClearLog();
int DeleteLog(int nLogCount);

class CLogClient
{
public:
    CLogClient();
    ~CLogClient();

    // Buile Message to send to Server, output the communicative struct in parameter "commStu"
    static bool AddLogBuildMessage(LOG_LEVEL nLogLevel, const std::string &strObj, const std::string &strDetailInfo, LOG_COMM_STU &commStu);
    static bool DelLogBuildMessage(LOG_LEVEL nLogLevel, int nCount, LOG_COMM_STU &commStu);
    static bool ClrLogBuildMessage(LOG_LEVEL nLogLevel, LOG_COMM_STU &commStu);
    static bool QueryLogBuildMessage(LOG_LEVEL nLogLevel, int nCount, const std::string &strKeyWord, const std::string &strStartDateTime, const std::string &strEndDateTime, LOG_COMM_STU &commStu);

    bool SendMessageToServer(const LOG_COMM_STU &commStu);
    bool GetRespondFromServer(std::string &strRspData);
    
    bool IsLogClientInit();
    int InitLogClient();

    bool LockMutex();
    bool UnLockMutex();

private:
    int m_socketFd;
    struct sockaddr_in m_ServerAddr;
    pthread_mutex_t *m_pAddLogMutex;
};

#endif